<extend name='Index/index' />

<block name="main">
    <div class="bg-light lter b-b wrapper-md">
        <h1 class="m-n font-thin h3">论坛管理 
        <if condition="in_array('Topic/topic_add',$access)">
        <button class="btn btn-default disabled" >新增帖子</button></h1>
        <else/>
        <a href="<{:U('Topic/topic_add')}>" class="btn btn-default" >新增帖子</a></h1>
        </if>
        </h1>
    </div>
    <div class="wrapper-md">
        <div class="panel panel-default">
            <div class="table-responsive">
                <table style="table-layout:fixed" class="table table-striped b-t b-light">
                    <thead>
                        <tr>
                            <th  width="4%"><div align='center'>ID</div></th>
                            <th  width="6%"><div align='center'>发帖人</div></th>
                            <th  width="10%"><div align='center'>标题</div></th>
                            <th  width="15%"><div align='center'>内容</div></th>
                            <th  width="5%"><div align='center'>回复数</div></th>
                            <th  width="8%"><div align='center'>发帖时间</div></th>
                            <th  width="8%"><div align='center'>最后回复时间</div></th>
                            <th  width="10%"><div align='center'>操作</div></th>
                        </tr>
                    </thead>
                    <tbody>
                        <foreach name="list" item="vo" key='k'>
                            <tr>
                                <td align='center'><{$vo.t_id}></td>
                                <td align='center'>
                                    <if condition="$vo.nickname"><{$vo.nickname}>
                                    <else/><{$vo.email}>
                                    </if>
                                </td>
                                <td align='center' style="overflow:hidden;white-space:nowrap;text-overflow:ellipsis;"><{$vo.title}></td>
                                <td align='center' style="overflow:hidden;white-space:nowrap;text-overflow:ellipsis;"><{$vo.content}></td>
                                <td align='center'><{$vo.reply_num}></td>
                                <td align='center'><{$vo.createtime|date="Y-m-d H:i:s",###}></td>
                                <td align='center'><{$vo.lasttime|date="Y-m-d H:i:s",###}></td>
                                <td align='center'>
                                <if condition="in_array('Topic/topic_edit',$access)">
                                <a href="#"  class="disabled btn" >编辑</a>
                                <else/>
                                <a href="<{:U('Topic/topic_edit',array('id'=>$vo[t_id]))}>"  class="btn btn-default">编辑</a>
                                </if>
                                <if condition="in_array('Topic/topic_del',$access)">
                                  <a href="" class="disabled btn">删除</a>
                                <else/>
                                  <a topic_id="<{$vo[t_id]}>" class="btn btn-default">删除</a>
                                </if>
                                </td>
                            </tr>
                        </foreach>
                    </tbody>
                </table>
            </div>
        </div>
        <{$page}>
        <p></p>
        <p></p>
    </div>
    <script>
        $("a:contains('删除')").click(function(){
            var tr = $(this).parents('tr');
            if (confirm('确认删除?')) {
                var tid = $(this).attr('topic_id');
                $.ajax({
                    url: "<{:U('Topic/topic_del')}>",
                    data:{'tid':tid},
                    type: 'get',
                    success: function(data){
                        // alert(data)
                        if (data == 1) {
                            alert('删除成功');
                            tr.remove();
                        }else{
                            alert('删除失败');
                        }
                    }
                })
            }
        })
    </script>
</block>

